<?php
/**
 * 基础配置文件
 *
 * 本文件包含以下配置选项：MySQL 设置、目录定义、TOP appKey和 appSecret 等基本定义
 *
 * @author		Tata <windzb@qq.com>
 *
 */


/*
 * --------------------------------------------------------------------
 * 应用所处的环境模式
 * --------------------------------------------------------------------
 *		local			本地授权模式
 *      sandbox			本地测试模式->沙箱模式
 *      run				正式模式
 *      run_url         正式模式 传递
 */

session_start();

set_time_limit(0);
date_default_timezone_set('PRC');
error_reporting(E_ALL^E_NOTICE);

header("Content-type: text/html; charset=utf-8");

if(!defined("DEV_MODE")) {
	define('DEV_MODE', 'local');
}


switch (DEV_MODE)
{
	//本地模式
	case 'local':

		define("DB_HOST","localhost");
		define("DB_USER","root");
		define("DB_PWD","");
		define("DB_NAME","MAC");

		define("MEM_HOST","localhost");
		define("MEM_USER","");
		define("MEM_PWD","");

        //顽兔空间名
        define("WANTU_NAMESPACE","vrbuy");
        define("WANTU_dir","MAC");
        define("WANTU_AK",23246224);
        define("WANTU_SK",'c1253bd619fad8ea02d68c283debdf2a');

		// ** TOP 设置  ** //
        /*define("appKey",23272568);
		define("appSecret",'9ad49c465c03fdfcd7f5011a929493ed');*/


		define("appKey",23732157);
		define("appSecret",'5eea79e31b91f177680329b08717f32e');

		define("appGateWay",'//gw.api.tbsandbox.com/router/rest');
		// ** 短授权地址  ** //
		define("LIMIT_AUTH_URL","https://oauth.taobao.com/authorize?response_type=code&client_id=".appKey."&redirect_uri=https://smart.ews.m.jaeapp.com");

		//站点域名:
		//define("SITE",$_taeServer);

		//$buyer_mix_nick = (empty($context->getBrowser()->nick))? "":$context->getBrowser()->nick;

		break;

	//线上模式
	case 'run':


		define("DOMAIN_NAME",'https://'.$_SERVER['SERVER_NAME']);

		define("DB_HOST","rdsmyabzfmyabzf.mysql.rds.aliyuncs.com");
		define("DB_USER","r4ktifnwex");
		define("DB_PWD","ra0is464");
		define("DB_NAME","app_db");

		define("MEM_HOST","3af1b25e89b111e4.m.jst.cnhzalicm10pub001jae001.ocs.aliyuncs.com");
		define("MEM_USER","3af1b25e89b111e4");
		define("MEM_PWD","123_Jae_ASD");

        //顽兔空间名
        define("WANTU_NAMESPACE","vrbuy");
        define("WANTU_dir","MAC");
        define("WANTU_AK",23246224);
        define("WANTU_SK",'c1253bd619fad8ea02d68c283debdf2a');

		// ** 卖家数据  ** //
		//define("SELLERID",$context->getSiteOwner()->getUserId());
		//define("SELLERNICK",$context->getSiteOwner()->getNick());

		// ** TOP 设置  ** //
        define("appKey",23732157);
        define("appSecret",'5eea79e31b91f177680329b08717f32e');

		define("appGateWay",'//gw.api.taobao.com/router/rest');
		// ** 短授权地址  ** //
		define("LIMIT_AUTH_URL","https://oauth.taobao.com/authorize?response_type=code&client_id=".appKey."&redirect_uri=https://smart.ews.m.jaeapp.com");

		//站点域名:
		//define("SITE",$_taeServer);

		//$buyer_mix_nick = (empty($context->getBrowser()->getMixNick()))? "":$context->getBrowser()->getMixNick();

		break;

	default:
		exit('应用环境设置错误或者未设置.');
		break;
}

/*
定义时区
*/
//date_default_timezone_set('PRC');

/*
 * --------------------------------------------------------------------
 * 店铺数据定义
 * --------------------------------------------------------------------
 *
 */
//define("SHOPID",$context->getSite()->getId);
/*
 * --------------------------------------------------------------------
 * 买家混淆nick
 * --------------------------------------------------------------------
 *
 */
//define("MIXNICK",$context->getBrowser()->getMixNick());
//define("BUYER_MIX_NICK",$buyer_mix_nick);
//define("BUYER_NICK",$context->getBrowser()->getNick);

/*
 * --------------------------------------------------------------------
 * 目录定义
 * --------------------------------------------------------------------
 *
 */
//define("DIR_SEP","/");  //TAE暂不支持 DIRECTORY_SEPARATOR ,所以自己定义一个.

//取得文件路径 TAE暂不支持dirname,所以自己写一个方法.
/*function get_dirname($path)
{
	$path = str_replace("\\","/",$path);	//避免淘宝用LINUX系统时出错,统一用 "/" 分割线.
	$pos = strripos($path, DIR_SEP );
	$path = substr($path,0,$pos);
	return $path;
}*/

//==站点根目录
define('BASE_PATH', dirname(__FILE__));
//TAE不支持dirname...
//define('BASE_PATH', get_dirname(__FILE__));

//==系统文件总目录
define("SYS_PATH",BASE_PATH);

//核心文件总目录
define("CORE_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."php/core");

//通用文件总目录
define("COMMON_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."php/common");

//类库总目录
define("LIBS_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."php/libs");

//控制页面总目录
define("CTRLS_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."php/controllers");

//模型页面总目录
define("MODELS_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."php/models");

//前台视图页面总目录
define("VIEWS_FRONT_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."front/views");

//后台视图页面总目录
define("VIEWS_ADMIN_PATH",SYS_PATH. DIRECTORY_SEPARATOR ."admin/views");




//==页面标题前缀
define("T_PREFIX","MAC管理后台");


//==其他定义
define("PNG_TAG_FIX",' class="J_TWidget" data-widget-type="Compatible" data-widget-config="{\'png\':true,\'png_tag\':true}" ');
define("PNG_BG_FIX",' data-widget-type="Compatible" data-widget-config="{\'png\':true,\'png_bg\':true}" ');



/*
 * --------------------------------------------------------------------
 * 载入方法文件
 * --------------------------------------------------------------------
 *
 */

include_once( COMMON_PATH . DIRECTORY_SEPARATOR ."Function.php");

include_once( COMMON_PATH . DIRECTORY_SEPARATOR ."P_Function.php");

// include_once(SYS_PATH.DIRECTORY_SEPARATOR."Services". DIRECTORY_SEPARATOR ."Autoload.php");

/*
 * --------------------------------------------------------------------
 * 运行Loader.php实例
 * --------------------------------------------------------------------
 *
 */
include_once( CORE_PATH . DIRECTORY_SEPARATOR ."Loader.php" );


/*
* --------------------------------------------------------------------
* 载入主控制器
* --------------------------------------------------------------------
*
*/
require_once CORE_PATH.'/Controller.php';
function &get_instance()
{
	return Controller::get_instance();
}
$TATA = new Controller();



/*
 * --------------------------------------------------------------------
 * 载入数据库db.php类
 * --------------------------------------------------------------------
 *
 */
include_once( LIBS_PATH . "/DB.php");

/*
 * --------------------------------------------------------------------
 * 载入主模型
 * --------------------------------------------------------------------
 *
 */
require_once CORE_PATH.'/Model.php';


/*
 * --------------------------------------------------------------------
 * 载入侧边小组件
 * --------------------------------------------------------------------
 *
 */
//require_once LIBS_PATH.'/Widget.php';




////////// 来路判断
//白名单模式 -- 可能会误伤正常访问
/*if(DEV_MODE != 'local'  &&
    !stristr($_SERVER['HTTP_REFERER'],'taobao.com')
    && !stristr($_SERVER['HTTP_REFERER'],'taobaoapps.net')
    && !stristr($_SERVER['HTTP_REFERER'],'sinxia.com')
    && !stristr($_SERVER['HTTP_REFERER'],'ecafe8.com')
)*/
//黑名单模式
if(isset($_SERVER["HTTP_REFERER"])) {
	if (stristr($_SERVER['HTTP_REFERER'], 'baidu.com')
		|| stristr($_SERVER['HTTP_REFERER'], 'google.com')
		|| stristr($_SERVER['HTTP_REFERER'], 'sogou.com')
		|| stristr($_SERVER['HTTP_REFERER'], 'soso.com')
		|| stristr($_SERVER['HTTP_REFERER'], 'youdao.com')
		|| stristr($_SERVER['HTTP_REFERER'], 'bing.com')
		|| stristr($_SERVER['HTTP_REFERER'], '360.cn')
	) {
		$s_site = "http://fuwu.taobao.com/ser/detail.htm?service_code=FW_GOODS-1887477";
		header("Location: " . $s_site);
	}
}